package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.*;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author iTaotao
 * @version 1.0
 * @Description
 * @createTime 2023年08月01日 14:11:00
 */
@Mapper
public interface UserMapper {
    /**
     * 查询用户openid
     *
     * @param openid openid
     * @return {@link User}
     */
    @Select("select * from user where openid = #{openid}")
    User selectUserByOpenId(String openid);

    /**
     * 插入用户
     *
     * @param user 用户
     */
    void insert(User user);

    /**
     * 选择类别列表
     *
     * @param type 类型
     * @return {@link Category}
     */

    List<Category> selectCategoryList(Integer type);

    /**
     * 选择菜列表
     *
     * @param categoryId 类别id
     * @return {@link List}<{@link DishVO}>
     */

    List<DishVO> selectDishList(Integer categoryId);

    /**
     * 选择套餐列表
     *
     * @param categoryId 类别id
     * @return {@link List}<{@link Setmeal}>
     */

    List<Setmeal> selectSetMealList(Long categoryId);

    /**
     * 选择套餐菜
     *
     * @param id id
     * @return {@link List}<{@link SetmealDish}>
     */

    List<DishItemVO> selectSetMealDish(Long id);

    /**
     * 选择商店购物车列表
     *
     * @return {@link List}<{@link ShoppingCart}>
     */

    /**
     * 选择口味
     *
     * @param dishId 菜id
     * @return {@link List}<{@link DishFlavor}>
     */
    @Select("select * from dish_flavor where dish_id = #{dishId}")
    List<DishFlavor> selectFlavor(Long dishId);

    /**
     * 添加购物车
     *
     * @param shoppingCartDTO 购物车dto
     */
    void add(ShoppingCartDTO shoppingCartDTO);

    /**
     * 选择一个
     *
     * @param shoppingCart 购物车
     * @return {@link ShoppingCart}
     */
    ShoppingCart selectOne(ShoppingCart shoppingCart);

    /**
     * 更新购物车购物
     *
     * @param cart 车
     */
    void updateShopCart(ShoppingCart cart);

    /**
     * 插入商店购物车
     *
     * @param cart 车
     */
    void insertShopCart(ShoppingCart cart);

    /**
     * 更新套餐商店购物车
     *
     * @param cart 车
     */
    void updateSetMealShopCart(ShoppingCart cart);

    /**
     * 插入套餐车
     *
     * @param cart 车
     */
    void insertSetMealCart(ShoppingCart cart);

    List<ShoppingCart> selectList(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     *
     * @param userId 用户id
     */
    @Delete("delete from shopping_cart where user_id= #{userId}")
    void clean(Long userId);

    /**
     * 选择商店购物车用户id
     *
     * @param userId 用户id
     * @return {@link ShoppingCart}
     */
    @Select("select * from shopping_cart where user_id = #{userId}")
    ShoppingCart selectShopCartByUserId(Long userId);

    /**
     * 删除一个
     *
     * @param setmealId setmeal id
     */
    @Delete("delete from shopping_cart where setmeal_id = #{setmealId} ")
    void deleteOne(Long setmealId);

    /**
     * 更新副本
     *
     * @param setmealDish setmeal菜
     */
    void updateCopies(SetmealDish setmealDish);


    /**
     * 删除数
     *
     * @param dishId 菜id
     */
    @Delete("delete from shopping_cart where dish_id = #{dishId}")
    void deleteNumber(Long dishId);

    /**
     * 更新num
     *
     * @param shoppingCart 购物车
     */
    void updateNum(ShoppingCart shoppingCart);

    /**
     * 选择套餐,套餐id
     *
     * @param setmealId setmeal id
     * @return {@link SetmealDish}
     */
    @Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
    SetmealDish selectSetMealBySetMealId(Long setmealId);

    void insertShopCartList(List<ShoppingCart> shoppingCartList);

    List<Map<String, Object>> selectUserStatistics(LocalDate begin, LocalDate end);

    Integer selectCountByCreateTime(Object date);
}
